package com.xiaoc.bulldozer.common.dto;

import com.xc.framework.common.utils.BeanUtil;
import com.xiaoc.bulldozer.common.converter.Converter;
import com.xiaoc.bulldozer.common.model.Appointment;

import javax.validation.constraints.NotNull;

/**
 * Appointment Dto
 *
 * @author wj
 *
 * @date 2019-04-29 09:49:19
 */
public class AppointmentDto extends Appointment {
    
    private static final long serialVersionUID = 1L;

    @NotNull(message = "验证码不能为空")
    private String verifyCode;

    private String productName;

    private String userName;

    public Appointment convertToAppointment(){
        AppointmentDTOConvert appointmentDTOConvert = new AppointmentDTOConvert();
        Appointment convert = appointmentDTOConvert.doForward(this);
        long now = System.currentTimeMillis();
        convert.setCreateTime(now);
        convert.setUpdateTime(now);
        return convert;
    }

    public AppointmentDto convertFor(Appointment appointment){
        AppointmentDTOConvert userDTOConvert = new AppointmentDTOConvert();
        AppointmentDto convert = userDTOConvert.doBackward(appointment);
        return convert;
    }

    public String getVerifyCode() {
        return verifyCode;
    }

    public void setVerifyCode(String verifyCode) {
        this.verifyCode = verifyCode;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    private static class AppointmentDTOConvert extends Converter<AppointmentDto, Appointment> {

        @Override
        protected Appointment doForward(AppointmentDto appointmentDto) {
            Appointment appointment = new Appointment();
            BeanUtil.copyProperties(appointment, appointmentDto);
            return appointment;
        }

        @Override
        protected AppointmentDto doBackward(Appointment appointment) {
            return null;
        }

    }
}
